package cn;

import cn.easthome.util.GlobalUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");
//获取系统时间
        long time = System.currentTimeMillis();
        //把系统时间转换成格式化字符串，响应给客户端
        String timeStr = GlobalUtil.getTime(time);
        //响应时间字符串
        response.getWriter().write(timeStr);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*super.doPost(req, resp);*/
        doGet(req, resp);
    }
}